/**
 *
 * @author 
 *
 */
class GameScene extends eui.Component{
    
    private scroller: eui.Group;
    public itemArr: ItemView[] = [];
    private canTouch = true;
    public timer1:eui.Image;
    public timer2: eui.Image;
    private timer3: eui.Image;
    private timer4: eui.Image;
    public timer: egret.Timer;          //总计时器
    private count1: number = 0;           //毫秒数
    private count2: number = 0;           //微妙
    public count: number;                //总时间
    

    private static _instance: GameScene;
    public static getInstance(): GameScene {
        if(GameScene._instance == null) {
            GameScene._instance = new GameScene();
        }
        return GameScene._instance;
    }
    
	public constructor() {
    	  super();
        this.skinName = "resource/skins/GameSceneSkin.exml";
	}
	
    public createChildren() {
        super.createChildren();
       this.init();
    }
    
    public timerFunc() {
        this.count--;
        if(this.count<10){
            this.timer1.source = "0_03";
            this.timer2.source = this.count.toString() + "_03";
        }else{
            this.timer1.source = this.count.toString().substring(0,1) + "_03";
            this.timer2.source = this.count.toString().substring(1,2) + "_03";
        }
    }
    
    public timeOver(){
        if(GameScene.getInstance().timer) {
            GameScene.getInstance().timer.stop();
            GameScene.getInstance().timer.removeEventListener(egret.TimerEvent.TIMER,GameScene.getInstance().timerFunc,this);
            GameScene.getInstance().timer.removeEventListener(egret.TimerEvent.TIMER_COMPLETE,GameScene.getInstance().timeOver,this);
            GameScene.getInstance().timer = null;
            Data.isrun = false;
        }
        if(Main.getInstance().contains(GameOverView.getInstance())) {

        } else {
            Main.getInstance().addChild(GameOverView.getInstance());
            GameOverView.getInstance().lb_results1.text = "您在规定的时间内找到了" + Data.grade.toString() + "部手机";
            var inp: InputPMView = new InputPMView();
            Main.getInstance().addChild(inp);
        }
    }
    public init(){
        this.scroller.removeChildren();
        GameScene.getInstance().count = 59;
        GameScene.getInstance().timer = new egret.Timer(1000,59);
        GameScene.getInstance().timer.addEventListener(egret.TimerEvent.TIMER,GameScene.getInstance().timerFunc,this);
        GameScene.getInstance().timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE,GameScene.getInstance().timeOver,this);
        this.timer1.source = "6_03";
        this.timer2.source = "0_03";
        for(var i = 0;i < 4;i++) {
            var item = new ItemView();
            item.name = "item" + i;
            item.horizontalCenter = 0
            item.y = 178 * i;
            item.switchIma();
            this.scroller.addChild(item);
            this.itemArr.push(item);
        }
        GameScene.getInstance().count = 59;
        GameScene.getInstance().timer = new egret.Timer(1000,59);
        GameScene.getInstance().timer.addEventListener(egret.TimerEvent.TIMER,GameScene.getInstance().timerFunc,this);
        GameScene.getInstance().timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE,GameScene.getInstance().timeOver,this);
    }
}
